﻿namespace NMortgage.UI.Tests
{
    using System;

    using FluentValidation.TestHelper;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Model;

    /// <summary>
    ///This is a test class for InterestParameterValidatorTest and is intended
    ///to contain all InterestParameterValidatorTest Unit Tests
    ///</summary>
    [TestClass]
    public class InterestParameterValidatorTest
    {
        #region Properties

        private InterestParameterValidator Subject
        {
            get;set;
        }

        private InterestParameter ValidationTarget
        {
            get; set;
        }

        #endregion Properties

        #region Methods

        [TestMethod]
        public void CantHaveInValidDistributionTest()
        {
            InterestParameterValidator_Accessor target = new InterestParameterValidator_Accessor();

            bool expected = false;
            bool actual;

            SetupFixedRateInterestInParam(ValidationTarget, 0d);

            actual = target.HaveValidDistribution(ValidationTarget, ValidationTarget.Distribution);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void CantHaveYearsMonthsGreaterThanZeroTest()
        {
            InterestParameterValidator_Accessor target = new InterestParameterValidator_Accessor();

            bool expected = false;
            bool actual;

            ValidationTarget.Years = 0;
            ValidationTarget.Months = 0;
            actual = target.HaveYearsMonthsGreaterThanZero(ValidationTarget, 0);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void HaveValidDistributionTest()
        {
            InterestParameterValidator_Accessor target = new InterestParameterValidator_Accessor();

            bool expected = true;
            bool actual;

            SetupFixedRateInterestInParam(ValidationTarget, 1d);

            actual = target.HaveValidDistribution(ValidationTarget,null);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void HaveYearsMonthsGreaterThanZeroTest()
        {
            InterestParameterValidator_Accessor target = new InterestParameterValidator_Accessor();

            bool expected = true;
            bool actual;

            ValidationTarget.Years = 0;
            ValidationTarget.Months = 1;
            actual = target.HaveYearsMonthsGreaterThanZero(ValidationTarget, 0);
            Assert.AreEqual(expected, actual);

            ValidationTarget.Years = 1;
            ValidationTarget.Months = 1;
            actual = target.HaveYearsMonthsGreaterThanZero(ValidationTarget, 0);
            Assert.AreEqual(expected, actual);

            ValidationTarget.Years = 1;
            ValidationTarget.Months = 0;
            actual = target.HaveYearsMonthsGreaterThanZero(ValidationTarget, 0);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void InterestParameterValidatorConstructorTest()
        {
            InterestParameterValidator target = new InterestParameterValidator();
            Assert.IsNotNull(target);
        }

        [TestInitialize]
        public void TestInitialize()
        {
            Subject = new InterestParameterValidator();
            ValidationTarget = new InterestParameter(DistributionType.FixedRate);
        }

        private static void SetupFixedRateInterestInParam(InterestParameter ip, double newRate)
        {
            ip.DistributionType = DistributionType.FixedRate;
            ((FixedRate)ip.Distribution).Rate = newRate;
        }

        #endregion Methods
    }
}